package com.sc.VenusQueryBeta.ui.fragments.hotel.child.tabs;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.hengjun.kingstar.sdk.base.BasePresenter;
import com.hengjun.kingstar.sdk.base.fragment.BaseRecycleFragment;
import com.hengjun.kingstar.sdk.utils.LogUtil;
import com.hengjun.kingstar.sdk.utils.LogUtils;
import com.sc.VenusQueryBeta.R;
import com.sc.VenusQueryBeta.adapter.home.PriceAdapter;
import com.sc.VenusQueryBeta.constant.Constants;
import com.sc.VenusQueryBeta.contract.hotel.tabs.PriceContract;
import com.sc.VenusQueryBeta.model.bean.home.HotelPriceBean;
import com.sc.VenusQueryBeta.model.bean.home.VipListBean;
import com.sc.VenusQueryBeta.presenter.hotel.tabs.PricePresenter;

import java.util.List;

import butterknife.BindView;

/**
 * 酒店价格fragment
 */

public class PriceFragment extends BaseRecycleFragment<PriceContract.PricePresenter> implements PriceContract.IPriceView {


    @BindView(R.id.rv_price)
    RecyclerView rvPrice;
    private VipListBean.DataBean.ClubListBean listBean;
    private PriceAdapter priceAdapter;
    private boolean isUpdate = false;

    public static PriceFragment newInstance() {
        return new PriceFragment();
    }

    @NonNull
    @Override
    public BasePresenter initPresenter() {
        return PricePresenter.newInstance();
    }

    @Override
    public void updateContentList(List<Object> list) {

    }

    @Override
    public void itemNotifyChanged(int position) {

    }

    @Override
    public void showHotelPriceDataSuccess(HotelPriceBean hotelPriceBean) {
        LogUtils.e("sdadsads==============="+hotelPriceBean.getData().get(0).getRoomList());
        if (priceAdapter.getData().size() == 0) {
            initRecycleview(hotelPriceBean);
        } else {
            if (isUpdate) {//
                priceAdapter.replaceData(hotelPriceBean.getData());
            } else {
                priceAdapter.addData(hotelPriceBean.getData());
            }
        }
    }

    @Override
    public void showNetworkError() {
    }

    @Override
    public void showLoadMoreError() {

    }

    @Override
    public void showNoMoreData() {

    }

    /**
     * 錯誤時請求回調
     * @param view view
     */
    @Override
    protected void onErrorViewClick(View view) {
            mPresenter.getHotelPriceData(listBean.getVipClubId());

    }

    @Override
    protected void showLoading() {
        priceAdapter.setEmptyView(loadingView);
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_price;
    }

    @Override
    public void initUI(View view, @Nullable Bundle savedInstanceState) {

        int result = 0;
        int resourceId = mContext.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = mContext.getResources().getDimensionPixelSize(resourceId);
            LogUtil.e("result========"+result);
        }

        priceAdapter = new PriceAdapter(R.layout.item_price);
        rvPrice.setAdapter(priceAdapter);
        rvPrice.setLayoutManager(new LinearLayoutManager(mActivity));
    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
            mPresenter.getHotelPriceData(listBean.getVipClubId());
    }
    /**
     * 填充酒店價格適配器
     * @param hotelPriceBean
     */
    private void initRecycleview(final HotelPriceBean hotelPriceBean) {
        priceAdapter = new PriceAdapter(R.layout.item_price, hotelPriceBean.getData());
        rvPrice.setAdapter(priceAdapter);
    }

    /**
     * 獲得傳過來的id值
     *
     * @param bundle
     */
    @Override
    public void getBundle(Bundle bundle) {
        if (bundle != null) {
            listBean = (VipListBean.DataBean.ClubListBean) bundle.getSerializable(Constants.VIP_CLUB_LIST);
//            ToastUtils.showToast(listBean.getClubName());
        } else {
//            ToastUtils.showToast("null");
        }
    }
}
